//
//  SubDistrictStatisticCell.m
//  YunGui
//
//  Created by Hanen 3G 01 on 16/3/31.
//  Copyright © 2016年 hanen. All rights reserved.
// 城市总监 小区统计

#import "SubDistrictStatisticCell.h"
#import "ViewTool.h"
#import "StatisticModel.h"
@interface SubDistrictStatisticCell ()
{
    CGFloat  space;
    UILabel * dotLabel;
    UILabel  *levelContentLabel;
    UILabel  *numContentLabel;
    UILabel  *percentContentLabel;
}
@end

@implementation SubDistrictStatisticCell

+ (instancetype)cellWithTabelView:(UITableView *)tableView
{
    static NSString *celId = @"SubDistrictStatisticCellID";
    SubDistrictStatisticCell *cell = [tableView dequeueReusableCellWithIdentifier:celId];
    if (!cell) {
        cell = [[SubDistrictStatisticCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:celId];
        [cell addSubviews];
    }
    return cell;
}

- (void)addSubviews
{
    
    CGFloat  labelW = (kScreenWidth - 2) / 3.0f;
    CGFloat cellH = [SubDistrictStatisticCell cellHeight];
    CGFloat  labelH = [UIView getHeight:20.0f];
//    CGFloat  biglabelH = [UIView getHeight:30.0f];
    space = [UIView getWidth:10];
    
   dotLabel = [[UILabel alloc] initWithFrame:CGRectMake(2.5 * space, 2 * space, 8, 8)];
    dotLabel.layer.cornerRadius = dotLabel.width / 2.0f;
    dotLabel.layer.masksToBounds = YES;
    dotLabel.backgroundColor = BlueColor;
    [self.contentView addSubview:dotLabel];
    
    _numLabel = [ViewTool getLabelWith:CGRectMake(dotLabel.maxX + 5, space * 1.5 - 3, 100, labelH) WithTitle:@" .. " WithFontSize:16.0f WithTitleColor:BLACKTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_numLabel];
    
    //等级标志
//    UILabel *levelLable = [ViewTool getLabelWith:CGRectMake(_numLabel.maxX + 2 * space, cellH - 2 * space - labelH, labelW, labelH) WithTitle:@"等级" WithFontSize:15.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
//    [self.contentView addSubview:levelLable];
    //是什么等级的 label
    levelContentLabel = [ViewTool getLabelWith:CGRectMake(0, _numLabel.maxY + space / 2.0f, labelW, labelH) WithTitle:@"" WithFontSize:20.0f WithTitleColor:UIColorFromRGB(0xff7703) WithTextAlignment:NSTextAlignmentCenter];
//    levelContentLabel.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:levelContentLabel];
    
    //等级标志
   self.levelLable = [ViewTool getLabelWith:CGRectMake(levelContentLabel.x, levelContentLabel.maxY ,labelW, labelH) WithTitle:@"等级" WithFontSize:15.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
//    levelLable.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.levelLable];
    
    UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(_levelLable.maxX, levelContentLabel.y + space, 1, _levelLable.height + levelContentLabel.height - 2 * space)];
    lineView1.backgroundColor = GRAYLINECOLOR;
    [self.contentView addSubview:lineView1];
    
    numContentLabel = [ViewTool getLabelWith:CGRectMake(lineView1.maxX , levelContentLabel.y, labelW, labelH) WithTitle:@"" WithFontSize:23.0f WithTitleColor:UIColorFromRGB(0xfebd2f) WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:numContentLabel];
    
    //等级标志
    UILabel *numLabel = [ViewTool getLabelWith:CGRectMake(numContentLabel.x, _levelLable.y,labelW, labelH) WithTitle:@"数量" WithFontSize:15.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:numLabel];
    
    UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(numContentLabel.maxX, lineView1.y, 1, lineView1.height)];
    lineView2.backgroundColor = GRAYLINECOLOR;
    [self.contentView addSubview:lineView2];
    
    percentContentLabel = [ViewTool getLabelWith:CGRectMake(lineView2.maxX , levelContentLabel.y, labelW, labelH) WithTitle:@"" WithFontSize:23.0f WithTitleColor:UIColorFromRGB(0x15409a) WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:percentContentLabel];
    
    UILabel *percentLabel = [ViewTool getLabelWith:CGRectMake(percentContentLabel.x, _levelLable.y,labelW, labelH) WithTitle:@"百分比" WithFontSize:15.0f WithTitleColor:GRAYCOLOR WithTextAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:percentLabel];
    
    UIView *bottomLine = [ViewTool getLineViewWith:CGRectMake(dotLabel.x, cellH - 1, kScreenWidth - 2 * dotLabel.x, 1) withBackgroudColor:GRAYLINECOLOR];
    [self.contentView addSubview:bottomLine];
    
}
- (void)setModel:(StatisticModel *)model{
    _model = model;
    
//    NSLog(@"%@",model.name);
    levelContentLabel.text = model.name;
    numContentLabel.text = [NSString stringWithFormat:@"%@",model.value];
    percentContentLabel.text = [NSString stringWithFormat:@"%.2f",model.percent];
    
}
+ (CGFloat)cellHeight
{
    return [UIView getWidth:90.0f];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    [super setHighlighted:highlighted animated:animated];
    dotLabel.backgroundColor = BlueColor;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
     dotLabel.backgroundColor = BlueColor;
    // Configure the view for the selected state
}

@end
